package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Users;
import service.LoginUserservice;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class LoginUserController {
private LoginUserservice LoginUserservice;

    public service.LoginUserservice getLoginUserservice() {
        return LoginUserservice;
    }

    public void setLoginUserservice(service.LoginUserservice loginUserservice) {
        LoginUserservice = loginUserservice;
    }

    @RequestMapping("/userlogin.do")
    public String login(Users users, HttpSession session) {
        System.out.println(""+users.getPassword());
        System.out.println(users.getUsername());
        System.out.println(users.toString());
        Users login = LoginUserservice.login(users);
        if (login != null) {
            session.setAttribute("id", login.getId());
            session.setAttribute("supper", login.getSupper());
            return "index";
        } else {
            session.setAttribute("yanzheng", "用户名或密码错误");
            return "login";
        }


    }
}
